package com.docking.heylo.web.controller;

import com.docking.heylo.constant.SystemConstant;
import com.docking.heylo.dao.entity.PersonalInformation;
import com.docking.heylo.dao.entity.UserApertureSet;
import com.docking.heylo.service.IUserService;
import com.docking.heylo.utils.HeyloMessageSource;
import com.docking.heylo.web.dto.CommonDto;
import com.docking.heylo.web.dto.EnrollmentDto;
import com.docking.heylo.web.dto.UpdatePasswordDto;
import com.docking.heylo.web.dto.UserArchive;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import com.docking.heylo.web.vo.LoginResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private HeyloMessageSource ms;

    @Autowired
    private IUserService userService;


    /***
     * 设置密码
     *
     * @return
     */
    @PostMapping("setPassword")
    public BaseVo setPassword(@RequestBody @Validated(EnrollmentDto.SetPassword.class) EnrollmentDto enrollmentDto){
        userService.setPassword(enrollmentDto);
        return ResultUtil.success(ms.getMessage("set_password.success"));
    }


    /***
     * 创建档案
     *
     * @return
     */
    @PostMapping("/createArchive")
    public BaseVo createArchive(@RequestBody UserArchive userArchive){
        userService.createArchive(userArchive);
        return ResultUtil.success(ms.getMessage("complete.data.success"));
    }


    /***
     * 获取个人信息
     *
     * @return
     */
    @PostMapping("/information")
    public BaseVo information(){
        LoginResult loginResult = userService.information();
        return ResultUtil.success(ms.getMessage(SystemConstant.success), loginResult);
    }


    /***
     * 获取他人个人信息
     *
     * @param pi
     * @return
     */
    @PostMapping("/informationById")
    public BaseVo informationById(@RequestBody PersonalInformation pi){
        LoginResult loginResult = userService.informationById(pi.getUserId());
        return ResultUtil.success(ms.getMessage(SystemConstant.success), loginResult);
    }

    /***
     * 修改用户信息
     * @param pi
     *
     * @return
     */
    @PostMapping("/saveInformation")
    public BaseVo saveInformation(@RequestBody PersonalInformation pi){
        userService.saveInformation(pi);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 同步定位
     *
     * @return
     */
    @PostMapping("/syncPositioning")
    public BaseVo syncPositioning(@RequestBody PersonalInformation pi){
        userService.syncPositioning(pi);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 申请成为大V
     *
     * @return
     */
    @PostMapping("/applyBigV")
    public BaseVo applyBigV(){
        userService.applyBigV();
        return ResultUtil.success(ms.getMessage("biga.apply"));
    }

    /***
     * 修改密码
     *
     * @return
     */
    @PostMapping("/updatePassword")
    public BaseVo updatePassword(@RequestBody UpdatePasswordDto passwordDto){
        userService.updatePassword(passwordDto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 首页逻辑条件塞选
     *
     * @return
     */
    @PostMapping("/aperture/setting")
    public BaseVo apertureSetting(@RequestBody UserApertureSet apertureSet){
        userService.apertureSetting(apertureSet);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }


    /**
     * 通过名称搜索摄影师或模特
     * @param commonDto 条件参数
     * @return {@link BaseVo}
     */
    @PostMapping("/searchByName")
    public BaseVo searchByName(@RequestBody CommonDto commonDto){
        List<Map<String,Object>> list = userService.searchByName(commonDto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success),list);
    }



}
